<template>
  <div>
        <selectYearAndTeam @okEvent="selectYearAndTeamOkEvent"  ref="selectReason"></selectYearAndTeam>
        <div class="my_socre_out_div"  style="background:url('./static/img/myscorebg.png')">
            <div class="my_socre_div" @click="toDetail(0)" style="background:url('./static/img/bg-Circle.png')">
              <span>{{fenAll}}分</span>
            </div>
        </div>
        <div  class="my_socre_detail_div"  >
            <div  class="socre_info_div" @click="toDetail(1)">
                <flexbox :gutter="0" >
                  <flexbox-item >
                      <span class="title">加分</span>
                  </flexbox-item>
                  <flexbox-item  align="right">
                       <span class="score">+{{fenAdd}}</span><icon type="enter" />
                  </flexbox-item>
                </flexbox>
            </div>
            <div  class="socre_info_div" @click="toDetail(2)">
                <flexbox :gutter="0" >
                  <flexbox-item >
                      <span class="title">扣分</span>
                  </flexbox-item>
                  <flexbox-item  align="right">
                       <span class="score">{{fenDelete}}</span><icon type="enter" />
                  </flexbox-item>
                </flexbox>
            </div>
        </div>
  </div>
</template>

<script>
import selectYearAndTeam  from '../../components/selectYearAndTeam.vue'
import scoreService from '../../shared/service/scoreService'
import weixinService from "../../shared/service/weixinService";
const wx = require('weixin-js-sdk')
import {  Group, Cell } from "vux";
export default {
   components: {
    selectYearAndTeam,   
    Group,
    Cell
  },
  data() {
    return {
      fenAll: 0,
      fenAdd: 0,
      fenDelete: 0,
      loginUserId:this.$cookie.getUserId(),
      startDateStr:null,
      endDateStr:null,
    };
  },
  mounted() {
    weixinService.initWx(wx);
  },
  methods: {
    selectYearAndTeamOkEvent(startDateStr,endDateStr) {
        this.startDateStr=startDateStr;
        this.endDateStr=endDateStr;
       scoreService.getStuScore(this.loginUserId,startDateStr,endDateStr).then((res)=>{
              var dataList = res.data;
              var fenALL = 0 ,fenAdd= 0,fenDelete= 0;
              for (let i = 0; i < dataList.length; i++) {
                  var po = dataList[i];
                  fenALL+=po.points;
                  if(po.points>=0){
                      fenAdd+=po.points;
                  }else{
                      fenDelete+=po.points;
                  }
              }
              this.fenAll=fenALL;
              this.fenAdd=fenAdd;
              this.fenDelete=fenDelete;
       });
    },
    toDetail(type) {
          this.$router.push({ name: "score_detail", query: { viewType: type,startDateStr:this.startDateStr,endDateStr:this.endDateStr } });
    },
  }
};
</script>

<style scoped>
@import '../../assets/scss/home.scss';
@import '../../assets/scss/score.scss';


</style>
